home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games: Greatest Hits 1996 / Amiga Games: Greatest Hits 1996.iso / archive / userbox / publicdomain / engclock_v7.0.lha / EngClock_v7.0 / EngClock7_Source / alarm.c < prev    next >
C/C++ Source or Header  |  1995-12-05  |  4KB  |  156 lines

  1. /* Main alarm routine(s) for EngClock */
  2.  
  3. //#include <proto/exec.h>
  4. #include <intuition/intuition.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. //#include <proto/intuition.h>
  9.  
  10. #include <clib/exec_protos.h>
  11. #include <clib/intuition_protos.h>
  12.  
  13. extern void msg(char *msg);
  14. extern BOOL talk(char *text);
  15. extern BOOL playsam(char *esvxname);
  16. extern char *trans(char *text);
  17. extern char *findday(int preset2);
  18. extern void gettime(void);
  19.  
  20. extern int memmins, memhours;
  21. extern char *engnums[60];
  22. extern char *days_data[7];
  23.  
  24. extern struct IntuiText req_text;
  25. extern struct IntuiText ok_text;
  26.  
  27. struct Event {
  28.     BOOL used;
  29.     int type;    /* Type of event */
  30.     int hours;    /* Time of event */
  31.     int minutes;
  32.     int timecode;
  33.     char message[256];
  34.     int day;
  35.     int month;
  36.     int year;
  37.     BOOL enabledate;
  38.     int freq;
  39. };
  40.  
  41. extern struct {
  42. /* Prefs structure used for preferences file format */
  43.  
  44.    char header[10];  /* I.D. Header */
  45.    int vers;         /* Version of preferences file */
  46.    int x;            /* X dimension of window when saved */
  47.    int y;            /* Y dimension of window when saved */
  48.    int width;        /* Width of window when saved */
  49.    int height;       /* Height of window when saved */
  50.    int planguage;    /* Language selected (menu) when saved, low pri */
  51.    int just;         /* Justification of text, 0=Left, 1=Centre */
  52.    short date;       /* Display date?, 0 = No, 1=Yes */
  53.    short wtf;         /* Window to front? */
  54.    int time_col[8];
  55.    int date_col[8];
  56.    short autoadjust;       /* Auto adjust ? */
  57.    char backdrop[256];
  58.    char pub[139];
  59.     char accent[256];        /* Language file for tRanslate */
  60.     char tkey[100];
  61.     char hkey[100];
  62.     struct Event events[11];  /* For the alarm! */ 
  63. }prefs;
  64.  
  65. extern struct {
  66. /* Time structure, set up by gettime() and used globally */
  67.  
  68.    int hours;        /* Number of hours since midnight on system clock */
  69.    int seconds;      /* Number of seconds */
  70.    int minutes;      /* Number of minutes */
  71.    int years;        /* Current year */
  72.    int days;         /* Date in current month */
  73.    int months;       /* Current month */
  74.    int wday;         /* Day in the week 0-6 (starting Sunday) */
  75. }time;
  76.  
  77.  
  78. void process_alarm(void) {
  79.     int i; BOOL flg=FALSE;
  80.  
  81.  
  82.  
  83.     /* Re-init the time structure */
  84.     gettime();
  85.  
  86.     for(i=1; i<=10; i++) {
  87.         if(prefs.events[i].used) {
  88.             if(!prefs.events[i].enabledate) 
  89.                 flg=TRUE;
  90.             else {
  91.                 switch(prefs.events[i].freq) {
  92.                     case 0: /* Daily */
  93.                         flg=TRUE;
  94.                     break;
  95.                     case 1: /* Once */
  96.                         if(prefs.events[i].day==time.days) {
  97.                             if(prefs.events[i].month==time.months) {
  98.                                 if(prefs.events[i].year==time.years) {
  99.                                     flg=TRUE;
  100.                                 }
  101.                             }
  102.                         }
  103.                     break;
  104.                     case 2: /* Weekly */
  105.                         if(!strcmp(findday(i),days_data[time.wday])) 
  106.                         flg=TRUE;
  107.                     break;
  108.                     case 3: /* Monthly */
  109.                         if(prefs.events[i].day==time.days)
  110.                             flg=TRUE;
  111.                     break;
  112.                     case 4: /* Yearly */
  113.                         if(prefs.events[i].day==time.days) {
  114.                             if(prefs.events[i].month==time.months) {
  115.                                 flg=TRUE;
  116.                             }
  117.                         }
  118.                     break;
  119.                     default:
  120.                     break;
  121.                 }
  122.             }
  123.             if(prefs.events[i].minutes==time.minutes) {
  124.                 if(prefs.events[i].hours==time.hours) {
  125.                     if(flg) {
  126.                         if(!(time.minutes==memmins && time.hours==memhours)) {
  127.                             switch(prefs.events[i].type) {
  128.                                 case 0:  /* Req */
  129.                                     req_text.IText=prefs.events[i].message;
  130.                                     ok_text.IText="Sure!";
  131.                                     AutoRequest(NULL,&req_text,NULL,&ok_text,NULL,NULL,320,100);
  132.                                 break;    
  133.                                 case 1:    /* Sound */
  134.                                     playsam(prefs.events[i].message);
  135.                                 break;
  136.                                 case 2:    /* Command */
  137.                                     system(prefs.events[i].message);
  138.                                 break;
  139.                                 case 3:    /* Talk */
  140.                                     talk(trans(prefs.events[i].message));
  141.                                 break;
  142.                                 default:
  143.                                     msg("Unknown event type!");
  144.                                 break;
  145.                             }
  146.                         }
  147.                     }
  148.                 }
  149.             }    
  150.         }
  151.     flg=FALSE; /* Remeber to set this back again dickbrains */
  152.     }
  153.     memmins=time.minutes;
  154.     memhours=time.hours;
  155. }
  156.